package com.eportal.controller.background;

import com.alibaba.fastjson.JSONObject;
import com.eportal.domain.Sysopt;
import com.eportal.service.CBuildingService;
import com.eportal.vo.controller.background.cbuilding.CBuildingSelectListVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 楼栋管理
 * Created by Saber on 2017/8/10.
 */
@Controller
@RequestMapping(value = "/admin/cbuilding")
public class CbuildingController {

    private static Logger logger = LoggerFactory.getLogger(CbuildingController.class.getName());

    @Resource
    private CBuildingService cBuildingService;

    /**
     * 楼栋下拉列表
     * @author Saber
     * @Date 2017/8/10 上午9:06
     * @param request
     * @param communityId       小区id
     * @return
     */
    @RequestMapping(value = "selectList.json")
    @ResponseBody
    public JSONObject selectList(HttpServletRequest request,String communityId){

        JSONObject json = new JSONObject();

        Sysopt user= (Sysopt)request.getSession().getAttribute("user");
        int userRole = (Integer)request.getSession().getAttribute("userRole");

        try {
            List<CBuildingSelectListVO> list=cBuildingService.selectList(communityId,user,userRole);
            json.put("code",1);
            json.put("msg","ok");
            json.put("data",list);
            return json;
        }catch (Exception e){
            e.printStackTrace();
            logger.error("获取楼栋列表（下拉）异常",e);
            json.put("code",0);
            json.put("msg","获取列表异常:"+e.getMessage());
            json.put("data",null);
            return json;
        }
    }
}
